package com.xc58.highreactor.seril;

import static com.xc58.highreactor.util.ByteUtil.getByteFormInt;
import static com.xc58.highreactor.util.ByteUtil.toInt;

import java.io.InputStream;

import com.xc58.highreactor.exception.ParseDataException;

public class IntSerializer implements ISerializer<Integer>{

	public byte[] serialize(Integer rawObject) throws Exception {
		return getByteFormInt(rawObject.intValue());
	}

	public Integer deserialize(InputStream input) throws Exception {
		byte[] bytes = new byte[4];
		if(input.read(bytes) < 4){
			throw new ParseDataException();
		}
		return toInt(bytes);
	}

}
